package com.zhuss.product.processor;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.product.hotLine.UpdateHotLineBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.product.db.dao.ext.HotLineDao;
import com.zhuss.product.db.entity.HotLine;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.util.JsonUtil;

/**
 * @description: 热门线路修改
 * @author: zhushanshuo
 * @create: Mon Jan 11 09:20:35 CST 2021
 **/
@Component("hotLineUpdate")
public class HotLineUpdate extends AbstractProcessor<Object, UpdateHotLineBo> implements Processor<Object, UpdateHotLineBo> {

    @Autowired
    private HotLineDao hotLineDao;
    
    @Autowired
	@Qualifier("hotLineRead")
	private HotLineRead hotLineRead;
    
    /**
     * 校验
     */
    @Override
    public void check(UpdateHotLineBo bo) throws DzcxException {
//    	// TODO 修改 热门线路 校验， 请补充
//
//    	Long hotLineId = bo.getHotLineId();
//    	String name = bo.getName();
//    	if (hotLineId == null || hotLineId <= 0l) {
//    		throw new DzcxException(ExceptionCode.热门线路ID为空);
//    	}
//    	if (name == null || "".equals(name.trim())) {
//    		// throw new DzcxException(ExceptionCode.热门线路name为空);
//    	}
//
//    	List<HotLine> list = hotLineRead.listNotId(name, hotLineId);
//    	if (!list.isEmpty()) {
//    		// throw new DzcxException(ExceptionCode.热门线路name已存在);
//    	}
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(UpdateHotLineBo param) {
    	HotLine record = new HotLine();
    	record.setHotLineId(param.getHotLineId());
    	record.setName(param.getName());
    	record.setHotLineNo(param.getHotLineNo());
    	record.setStartPointName(param.getStartPointName());
    	record.setEndPointName(param.getEndPointName());
    	record.setFirstTime(param.getFirstTime());
    	record.setRideType(param.getRideType());
    	record.setTotal(param.getTotal());
    	record.setSelled(param.getSelled());
    	record.setStatus(param.getStatus());
    	record.setPrice(param.getPrice());
    	record.setSort(param.getSort());

    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	hotLineDao.updateByPrimaryKeySelective(record);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(UpdateHotLineBo param) throws DzcxException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.商品.key());
    	record.setAction(LogActionEnum.热门线路修改.key());
    	record.setTargetId(param.getHotLineId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
